package leetcode.f1t100;

/**
 * 判断是否回文数
 *
 * https://leetcode.com/problems/regular-expression-matching/
 *
 * @author lichx
 * @date 2021/9/26 17:14
 */
public class Q9_PalindromeNumber {

    public static boolean isPalindrome(int x) {
        if (x < 0) {
            return false;
        }
        if (x < 10) {
            return true;
        }
        int length = 1;
        int t = x;
        while ((t /= 10) > 0) {
            length++;
        }
        int L = 1, R = length;
        while (L < R) {
            int e = (int) Math.pow(10, R - L);
            if (x / e != x % 10) {
                return false;
            }
            x = (x - x / e * e) / 10;
            L++;
            R--;
        }
        return true;
    }

    public static boolean awesome(int x) {
        if (x < 0 || (x != 0 && x % 10 == 0)) {
            return false;
        }
        int reverse = 0;
        while (x > reverse) {
            reverse = reverse * 10 + x % 10;
            x /= 10;
        }
        return (x == reverse || x == reverse / 10);
    }

    public static void main(String[] args) {
        System.out.println(isPalindrome(111));
    }
}
